package com.tgjorgoski.sidekicknotes.htmlview;

import javax.swing.text.*;
import javax.swing.text.html.*;

public class HTMLEditorKitChanged extends HTMLEditorKit {

	@Override
	public Document createDefaultDocument() {
		StyleSheet styles = getStyleSheet();
		StyleSheet ss = new StyleSheet();

		ss.addStyleSheet(styles);

		HTMLDocument doc = new HTMLDocChanged(ss);
		doc.setParser(getParser());
		doc.setAsynchronousLoadPriority(4);
		doc.setTokenThreshold(100);
		return doc;
	}

	private HTMLFactory htmlF = new HTMLFactory() {
		public View create(Element elem) {
			AttributeSet attrs = elem.getAttributes();
			Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
			Object o = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
			if (o instanceof HTML.Tag) {
				HTML.Tag kind = (HTML.Tag) o;
				if (kind == HTML.Tag.HR) {
					return new HRulerChanged(elem);
				}
			}
			return super.create(elem);
		}
	};

	@Override
	public ViewFactory getViewFactory() {
		return htmlF;
	}

}
